module Helpers
  # Loads a file from url, either using HTTP#get or File#read, if local
  def self.load_from_url(url)
    #TODO do some caching
	
    #if url begins with http://domain:port or http://localhost:port, read from file system
    if url=~ /^http:\/\/(localhost|#{Merb::Config[:host_name]}):#{Merb::Config[:port]}/	
	  File.read("#{Merb::Config[:merb_root]}/public/#{url.sub(/^http:\/\/.*:\d+\//,"")}")
	else
	  Net::HTTP.get(URI.parse(url))
	end
  end
end